﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resto.CostControl.Core.Query.MaterialModule.ViewObject;
using Enterprise.Framework.Frame.Architecture;
using Enterprise.Framework.DomainModel.Repositories;
using Resto.CostControl.Core.Domain.Model;
using Enterprise.Framework.DomainModel.Specifications;
using Enterprise.Framework.DomainModel;

namespace Resto.CostControl.Core.Query.MaterialModule.QueryObject
{
    public class MaterialProcessQO : IApplicationQueryObject
    {
        private IQueryable<MaterialProcessVO> GetMaterialProcessVOSet()
        {
            IEntityRepository<MaterialProcess> repository = RestoCostDomainSession.CurrentSession.CreateEntityRepository<MaterialProcess>();

            IQueryable<MaterialProcessVO> list = from o in repository.Objects
                                                 select new MaterialProcessVO()
                                                 {
                                                     ID = o.ID,
                                                     Code = o.Code,
                                                     ProcessDate = o.ProcessDate,
                                                     OrderStateCode = o.OrderState,
                                                 };

            return list;
        }

        public MaterialProcessVO[] QueryMaterialProcessVOByPager(ISpecification<MaterialProcessVO> spec, PagerCondition pager, string orderKey, bool isAscending)
        {
            IQueryable<MaterialProcessVO> list = GetMaterialProcessVOSet();

            if (spec != null)
                list = list.Where(spec.GetExpression());

            IEnumerable<MaterialProcessVO> list2 = RepositoryExtention.Query(list, pager, orderKey, isAscending);
            return list2.ToArray();
        }
    }
}
